package com.ithinkstudio.jeez.aspect;

import com.ithinkstudio.jeez.aspect.annotation.DataRole;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @program: jeez-springboot-bucket
 * @description: 数据权限过滤
 * @author: fengzp
 * @create: 2020/04/21
 */
@Component
@Aspect
@Order(10)
@Slf4j
public class DataFilterAspect {

    @Pointcut(value = "@annotation(com.ithinkstudio.jeez.aspect.annotation.DataRole)")
    public void access() {

    }

    @Before("access()")
    public void deBefore(JoinPoint joinPoint) throws Throwable {
        log.debug("开始权限拦截！");
    }

    @Around("@annotation(dataRole)")
    public Object around(ProceedingJoinPoint pjp, DataRole dataRole) {
        //获取注解里的值
        System.out.println("数据角色:" + dataRole.value());
        try {
            return pjp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return null;
        }
    }
}
